<template>
  <div>
    <h2>父组件</h2>
    <button @click="handclick">获取子组件数据，或者调用子组件方法</button>
    <hr />
    <Child />
  </div>
</template>

<script>
import Child from './Child.vue'
export default {
  name: 'childrenParent',
  data() {
    return {
      num: 23
    }
  },
  components: { Child },
  methods: {
    handclick() {
      console.log(this.$children[0].num) // 获取子组件数据
      this.$children[0].fn()
    },
    fn() {
      console.log('调用父组件方法')
    }
  }
}
</script>

<style lang="scss" scoped></style>
